package com.softer.chengxin.sysscore.dao.provider;

import com.softer.chengxin.common.domin.Page;
import com.softer.chengxin.sysscore.entity.SysScoreTypeDTO;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;

/**
 * @author zcz
 * @date 2018/12/12
 */
public class SysScoreTypeDaoProvider {
    public String getScoreTypeList(HashMap<String, Object> map) {
        StringBuffer sql = new StringBuffer(20);
        Page page = (Page) map.get("page");
        SysScoreTypeDTO scoreTypeDTO = (SysScoreTypeDTO) map.get("scoreTypeDTO");
        sql.append("SELECT s.id,s.`score_name` AS scoreName,s.`max_score` AS maxScore,s.`type` AS scoreType,s.`adder`,DATE_FORMAT(s.add_time, '%Y-%m-%d') AS `addTime` FROM score_type s ");
        sql.append(" where s.type=#{scoreTypeDTO.scoreType} ");
        if (StringUtils.isNotBlank(scoreTypeDTO.getId())) {
            sql.append(" AND s.id=#{scoreTypeDTO.id} ");
        }
        sql.append(" LIMIT ");
        sql.append(page.getBeginIndex()).append(",").append(page.getLimit());
        return sql.toString();
    }

    /**
     * 修改角色信息
     * @param scoreTypeDTO
     * @return
     */
    public String update(SysScoreTypeDTO scoreTypeDTO) {
        StringBuffer sql = new StringBuffer(20);
        sql.append("UPDATE score_type SET add_time=NOW() ");
        if(StringUtils.isNotBlank(scoreTypeDTO.getScoreType())){
            sql.append(" ,type=#{scoreType} ");
        }
        if(StringUtils.isNotBlank(scoreTypeDTO.getScoreName())){
            sql.append(" ,score_name=#{scoreName} ");
        }
        if(StringUtils.isNotBlank(scoreTypeDTO.getMaxScore())){
            sql.append(" ,max_score=#{maxScore} ");
        }
        sql.append(" where id=#{id}");
        return sql.toString();
    }
}
